package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.OptionalInt;

@Service
public class CourseTeacherServiceImpl implements CourseTeacherService {
    @Autowired
    CourseTeacherMapper courseTeacherMapper;

    @Override
    public List<CourseTeacher> getTeacher(Long id){
        LambdaQueryWrapper<CourseTeacher> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CourseTeacher::getCourseId,id);
        return courseTeacherMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public CourseTeacher addTeacher(CourseTeacher courseTeacher){
        courseTeacherMapper.insert(courseTeacher);
        return courseTeacher;
    }

    @Override
    public CourseTeacher updateTeacher(CourseTeacher courseTeacher){
//        LambdaQueryWrapper<CourseTeacher> lambdaQueryWrapper=new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(CourseTeacher::getId,courseTeacher.getId());
//        lambdaQueryWrapper.eq(CourseTeacher::getCourseId,courseTeacher.getCourseId());
        courseTeacherMapper.updateById(courseTeacher);
        return courseTeacher;
    }

    @Override
    public void deleteTeacher(Long courseId,Long teacherId){
        LambdaQueryWrapper<CourseTeacher> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CourseTeacher::getId,teacherId);
        lambdaQueryWrapper.eq(CourseTeacher::getCourseId,courseId);
        courseTeacherMapper.delete(lambdaQueryWrapper);
        return;
    }

}
